package LC;

/**
 * @ClassName LC.LC5
 * @Description: TODO
 * @Author hl
 * @Date 2020/5/21
 * @Version V1.0
 **/
public class LC5 {
    String res="";
    int len=0;
    public String longestPalindrome(String s) {
        if(s==null||s.length()==0){
            return  res;
        }
        for(int i=0;i<s.length();i++){
            find(s,i,i);
            find(s,i,i+1);
        }
        return  res;
    }

    private void find(String s, int i, int j) {
        while(i>=0&&j<=s.length()-1&&s.charAt(i)==s.charAt(j)){
            if(len<j-i+1){
                len=j-i+1;
                res=s.substring(i,j+1);
            }
            i--;
            j++;
        }

    }
}
